import _layer from "../../common/_layer";
import _series from "../../cache/_series";
import _location from "../../cache/_location";
import _city from "../../cache/_city";
import lib_car from "../../api/lib_car";
import _activity from "../../cache/_activity";
import _multiple_ui from "../../cache/_multiple_ui";


Page({
  data: {
    /**页面参数 */
    activity_id: '794', //活动ID
    brand_list: [], //车型列表
    province: '', //省
    city: '', //城市
    location: '', //定位
  },

  onLoad: function (options) {

  },
  onShow() {
     //存参数
    //  _activity.set({
    //   'activity_id': this.data.activity_id,
    //   'tids': 0,
    //   'clickid': ''
    // })
    _multiple_ui.set({
      'is_multiple': 1
    })
    this.init_car()

    console.log(this.data.activity_id, '活动id');
  },

  init_car() {
    lib_car.hot().then((res)=>{
      if (res.code != 0) {
        _layer.message(res.msg);
        return;
      }
      this.setData({
        brand_list: res.data,
      })
    })
  },
  //定位
  get_localCity(e) {
    this.getLocation(e)
  },

  getLocation(e) {
    const { id, name } = e.currentTarget.dataset.item
     //存对应的车型
     _series.set({ 'series_name': name, 'series_id': id })
    tt.getLocation({
      type: 'gcj02',
      success: (res) => {
        if (res.errMsg == 'getLocation:ok') {
          if (res.city) {

            _location.set(res.city)
            //存city
            _city.set(res.city)
          }
        }
      },
      fail: (errMsg) => {
        if (errMsg) {
          // _layer.message('已拒绝开启定位')
        }
      },
      complete:()=>{
        tt.navigateTo({
          url: `/packageMy/pages/pricelist/pricelist`,
        });
      }
    });
  },

  //分享
  async onShareAppMessage(option) {
    return {
      title: '查询底价',
      path: `/pages/home/home`, // ?后面的参数会在转发页面打开时传入onLoad方法
      success(res) {
        console.log('分享成功', res);
      },
      fail() {
        console.log("转发发布器调起失败");
      },
    };
  },


  // to_single_list() {
  //     tt.navigateTo({
  //       url: `/pages/single/list/list?activity_id=${this.data.activity_id}&tids=${this.data.tids}&clickid=${this.data.clickid}`,
  //     });
  // }

});